package com.chb.friend2;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class FofReducer extends Reducer<Fof, IntWritable, Text, IntWritable>{
	
	@Override
	protected void reduce(Fof key, Iterable<IntWritable> values, Context context)
			throws IOException, InterruptedException { 
		int sum = 0;
		for (IntWritable iw : values) {
			if (iw.get() == 0) {//出现值为0的fof为直接好友，不用统计了
				return;
			}
			sum += iw.get();
		}
		//输出Fof ab和ba
		context.write(key, new IntWritable(sum));
		String keyTmp = key.toString().split("\t")[1]+"\t"+key.toString().split("\t")[0];
		context.write(new Text(keyTmp), new IntWritable(sum));
	}
}
